package com.livegoods.service;

import com.livegoods.pojo.LivegoodsResult;
import com.livegoods.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public LivegoodsResult findOrdersByUser(String user) {

        try {
            Query query = new Query(Criteria.where("user").is(user));

            List<Order> orderList = mongoTemplate.find(query, Order.class);

            return  LivegoodsResult.ok(orderList);
        } catch (Exception e) {
            e.printStackTrace();
            return LivegoodsResult.error("查询订单失败，请联系管理员!");
        }

    }
}
